package com.jsmile.cloud.accountcenter.account.model;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.jsmile.cloud.accountcenter.api.req.address.ReqAddressSave;
import com.jsmile.cloud.accountcenter.api.req.address.ReqAddressUpdate;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2020年06月04日 04:38:37
 */
@ApiModel
@Data
@TableName("t_ac_user_address")
public class UserAddress extends Model<UserAddress> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    @ApiModelProperty(value = "用户id")
    private Long userId;
    @ApiModelProperty(value = "店铺id")
    private Long shopId;
    @ApiModelProperty(value = "联系人名称")
    private String contactName;
    @ApiModelProperty(value = "手机号码")
    private String phone;
    @ApiModelProperty(value = "省")
    private String province;
    @ApiModelProperty(value = "市")
    private String city;
    @ApiModelProperty(value = "区")
    private String district;
    @ApiModelProperty(value = "街道及详细地址")
    private String detailAddress;
    @ApiModelProperty(value = "邮编")
    private String zip;
    @ApiModelProperty(value = "纬度")
    private java.math.BigDecimal latitude;
    @ApiModelProperty(value = "经度")
    private java.math.BigDecimal longitude;
    @ApiModelProperty(value = "区域编码")
    private String adcode;
    @ApiModelProperty(value = "创建者")
    private String createBy;
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    @ApiModelProperty(value = "更新者")
    private String updateBy;
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;
    @ApiModelProperty(value = "是否默认地址")
    private Integer hasDefault;
    @ApiModelProperty(value = "是否删除")
    @TableLogic
    private Integer delFlag;
    @ApiModelProperty(value = "地址类型 1用户地址 2店铺地址")
    private Integer addressType;
    @ApiModelProperty(value = "租户id")
    private Long tenantId;
    @ApiModelProperty(value = "平台id")
    private Integer platformId;
    @ApiModelProperty(value = "业务id")
    private Integer bizCode;

    public static UserAddress create(ReqAddressSave reqAddressSave) {
        UserAddress userAddress = BeanUtil.toBean(reqAddressSave, UserAddress.class);
        userAddress.setCreateTime(new Date());
        userAddress.setUserId(reqAddressSave.getCurUserId());
        userAddress.setTenantId(reqAddressSave.getCurTenantId());
        // DomainEventPublisher.publish(new MemberRegisterEvent(userAddress));
        return userAddress;
    }

    public void changeUserAddress(ReqAddressUpdate reqAddressUpdate) {
        this.setUpdateTime(new Date());
        this.setProvince(reqAddressUpdate.getProvince());
        this.setCity(reqAddressUpdate.getCity());
        this.setDistrict(reqAddressUpdate.getDistrict());
        this.setDetailAddress(reqAddressUpdate.getDetailAddress());
        this.setContactName(reqAddressUpdate.getContactName());
        this.setPhone(reqAddressUpdate.getPhone());
        this.setLatitude(reqAddressUpdate.getLatitude());
        this.setLatitude(reqAddressUpdate.getLatitude());
        this.setUserId(reqAddressUpdate.getCurUserId());
        this.setTenantId(reqAddressUpdate.getCurTenantId());
        // DomainEventPublisher.publish(new MemberRegisterEvent(userAddress));
    }

    public void deleteUserAddress() {
        // DomainEventPublisher.publish(new MemberRegisterEvent(userAddress));
    }
}
